package com.han.bom;

import java.util.ArrayList;

/**
 * An extension of the User. Represents the administrative user of the system.
 * 
 * @author Nicol Angelo A. Santos
 * @version 1.0
 * @since JDK 1.7
 * @see User
 */
public class Professor extends User {
	private ArrayList<Student> students;
	private ArrayList<Exam> exams;
	private static int totalProfessors = 0;
	
	/**
	 * Constructor
	 * Initializes the user id of the professor.
	 * 
	 * @param userID
	 * @see User
	 * 
	 */
	public Professor(int userID) {
		super("P"+userID);
		totalProfessors++;
	}

	/**
	 * Returns the list of Students of a certain Professor
	 * 
	 * @return
	 */
	public ArrayList<Student> getStudents() {
		return students;
	}

	/**
	 * Sets the list of Students of a certain Professor
	 * 
	 * @param students
	 */
	public void setStudents(ArrayList<Student> students) {
		this.students = students;
	}

	/**
	 * Returns the list of Exams made by a certain Professor
	 * 
	 * @return
	 */
	public ArrayList<Exam> getExams() {
		return exams;
	}

	/**
	 * Sets the list of Exams made by a certain Professor
	 * 
	 * @param exams
	 */
	public void setExams(ArrayList<Exam> exams) {
		this.exams = exams;
	}
	
	/**
	 * Returns an Exam from the list of exams through the given Exam Id
	 * 
	 * @param examID
	 * @return
	 */
	public Exam searchExam(String examID){
		
		Exam found = null;
		
		for(Exam exam: exams){
			if(exam.getExamID()==examID){
				found = exams.get(exams.indexOf(exam));
				break;
			}
		}
		
		return found;
	}
	
	/**
	 * Returns an Exam from the list of exams through the exam object
	 * 
	 * @param exam
	 * @return
	 */
	public Exam searchExam(Exam exam){
		Exam found = null;
		
		if(exam!=null){
			found = searchExam(exam.getExamID());
		}
			
		return found;
	}
	
	/**
	 * Returns a Student from the list of students through its student id
	 * 
	 * @param studentID
	 * @return
	 */
	public Student searchStudent(String studentID){
		Student student = null;
		
		for(Student s: students){
			if(s.getUserID().equals(studentID)){
				student = students.get(students.indexOf(s)); 
				break;
			}
		}
		
		return student;
	}
	
	/**
	 * Returns a Student from the list of students through the student object
	 * 
	 * @param student
	 * @return
	 */
	public Student searchStudent(Student student){
		Student found = null;
		
		if(student!=null){
			found = searchStudent(student.getUserID());
		}
			
		return found;
	}
	
	/**
	 * Returns an exam made by the professor. If the adding is successful,
	 * it will add to the list of exams of the professor.
	 * 
	 * @param examType
	 * @return
	 */
	public Exam createExam(String examType){
		Exam exam = null;
		
		if(examType.equals("RE")){
			exam = new RealExam();
		}else if(examType.equals("PE")){
			exam = new PracticeExam();
		}
		
		exams.add(exam);
		exam = exams.get(exams.indexOf(exams));
		
		return exam;
	}
	
	/**
	 * It is a method to change the Real Exam's Activation status to true
	 * so that students can take the selected exam.
	 * 
	 * @param realExam
	 */
	public void activateExam(RealExam realExam){
		realExam.setActivated(true);
	}
	
	/**
	 * It is a method to change the Real Exam's Activation status to false
	 * so that students can take the selected exam.
	 * 
	 * @param realExam
	 */
	public void deactivateExam(RealExam realExam){
		realExam.setActivated(false);
	}

	public static int getTotalProfessors() {
		return totalProfessors;
	}

	public static void setTotalProfessors(int totalProfessors) {
		Professor.totalProfessors = totalProfessors;
	}
	
}
